package com.blb;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 计算机
 */
@Component
public class Computer {

    //品牌
    @Value("苹果")
    private String brand;

    //cpu 依赖
    //Autowire 默认按类型注入，Resource 默认按名字注入，名字找不到再按类型； Autowire是Spring的注解 Resource是Java的注解
    @Resource
    private Cpu cpu;

    //内存 依赖
    @Qualifier("s")
    @Autowired
    private Memory memory;

    public Computer() {
    }

    public Computer(String brand, Cpu cpu, Memory memory) {
        this.brand = brand;
        this.cpu = cpu;
        this.memory = memory;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        System.out.println("调用了setBrand");
        this.brand = brand;
    }

    public Cpu getCpu() {
        return cpu;
    }

    public void setCpu(Cpu cpu) {
        System.out.println("调用了setCpu");
        this.cpu = cpu;
    }

    public Memory getMemory() {
        return memory;
    }

    public void setMemory(Memory memory) {
        System.out.println("调用了setMemory");
        this.memory = memory;
    }

    //启动
    public void start(){
        System.out.println(brand+"品牌的电脑启动了");
        cpu.run();
        memory.read();
        memory.write();
    }
}
